#include <graphics/indexbuffer.h>
#include <graphics/utils.h>
#include <QtOpenGL>

namespace yam3d
{
namespace graphics
{

IndexBuffer::IndexBuffer( const core::vector<unsigned int>& indices)
    : core::Object(__FUNCTION__)
    , m_indices(indices)
{
    assert( (indices.size()%3) == 0 );
}

IndexBuffer::~IndexBuffer()
{
}

void IndexBuffer::draw()
{
    glDrawElements ( GL_TRIANGLES, m_indices.size(), GL_UNSIGNED_INT, m_indices.constData() );
    checkGlError("glDrawElements");
}

void IndexBuffer::getIndices(core::vector<unsigned int>* indices)
{
    indices->resize(m_indices.size());
    for (int i=0; i<m_indices.size(); ++i )
    {
        (*indices)[i] = m_indices[i];
    }

    assert( (indices->size()%3) == 0 );
}

}
}

